package com.itbaizhan.shopping_manager_api.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itbaizhan.shopping_common.pojo.SeckillGoods;
import com.itbaizhan.shopping_common.result.BaseResult;
import com.itbaizhan.shopping_common.service.SeckillGoodsService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

/**
 * 秒杀商品控制层
 */
@RestController
@RequestMapping("/seckillGoods")
public class seckillGoodsController {
	
	@DubboReference
	private SeckillGoodsService seckillGoodsService;
	
	/**
	 * 添加秒杀商品
	 * @param seckillGoods 秒杀商品实体
	 * @return
	 */
	@PostMapping("/add")
	public BaseResult add(@RequestBody SeckillGoods seckillGoods){
		seckillGoodsService.add(seckillGoods);
		return BaseResult.ok();
	}
	
	/**
	 * 修改秒杀商品
	 * @param seckillGoods 秒杀商品实体
	 * @return
	 */
	@PutMapping("/update")
	public BaseResult update(@RequestBody SeckillGoods seckillGoods){
		seckillGoodsService.update(seckillGoods);
		return BaseResult.ok();
	}
	
	/**
	 * 查询秒杀商品列表
	 * @param page 当前页码
	 * @param size 每页条数
	 * @return 查询结果
	 */
	@GetMapping("/findPage")
	public BaseResult<Page<SeckillGoods>> findPage(int page, int size){
		Page<SeckillGoods> page1 = seckillGoodsService.findPage(page, size);
		return BaseResult.ok(page1);
	}
}
